'use strict';

module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const Orders = app.model.define('orders', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    orderNumber: STRING(20),
    userId: INTEGER,
    houseId: INTEGER,
    isPayed: {
      type: INTEGER,
      defaultValue: 0,
    },
    createTime: {
      type: DATE,
    },
    updateTime: {
      type: DATE,
    },
  });

  Orders.associate = () => {
    app.model.Orders.belongsTo(app.model.Houses, {
      foreignKey: 'houseId',
      as: 'houses',
    });
  };

  return Orders;
};
